var api = {
    /**
     * 是否登录
     * @returns boolen
     */
    checkLogin() {
        if (api.getCookie('token')) {
            return true;
        } else {
            return false;
        }
    },
    /**
     * 刷新
     *
     */
    refresh() {
        location.reload()
    },
    /**
     * 设置指定cookie到“/”作用域
     * @param {type} cname key值
     * */
    setCookie(cname, value) {
        let key = cname + '='
        document.cookie = key + value + ";path=/";
    },
    /**
     * 获取指定cookie
     * @param {type} cname key值
     * */
    getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
        return "";
    },
    /**
     * 清楚所有cookie
     *
     * */
    clearAllCookie() {
        var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
        if (keys) {
            for (var i = keys.length; i--;)
                document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString() + ";path=/"
            if (window.opener) {
                // window.opener.document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()

            }

        }
    },

}

export default api
